package main

import (
	"fmt"
	"net"
	"time"
)

func main() {
	fmt.Println("client start...")
	//连接服务器
	conn,err := net.Dial("tcp","127.0.0.1:8999")
	if err != nil{
		fmt.Printf("dial error:%v\n",err)
		return
	}
	//休息一秒，让服务器那边先启动服务器
	time.Sleep(1 * time.Second)
	buf := make([]byte,512)

	//每隔一秒给服务器那边发送数据，并接收服务器发送过来的数据
	for{
		_,err := conn.Write([]byte("hello zinx v0.2..."))
		if err != nil{
			fmt.Printf("client write to server error:%v\n",err)
			return
		}
		//接收服务器那边发送过来的数据
		n,err := conn.Read(buf)
		if err != nil{
			fmt.Printf("client read from server error:%v\n",err)
			return
		}
		fmt.Printf(" server call back:%s, n = %d\n",buf[:n],n)
		time.Sleep(1 * time.Second)
	}
}